﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

using AutoFacUtils;
using FluentValidation;
using CashFlow.Web.Models.Order;
using CashFlow.Web.Common;
using CashFlow.Web.Service;

namespace CashFlow.Web.Validator.Order
{
    public class ViewSellerInfoModelValidator
        : AbstractValidator<ViewSellerInfoModel>
    {
        private IOrderService GetOrderService() { return AutoFacHelper.Get<IOrderService>(); }
        private IUserService GetUserService() { return AutoFacHelper.Get<IUserService>(); }

        public ViewSellerInfoModelValidator()
        {
            RuleFor(x => x.OrderId).Must((x, y) => IsLegalBuySellInfo(x.OrderId, x.SellerUserId))
                .WithMessage("非法OrderId & SellerUserId");
        }

        private bool IsLegalBuySellInfo(int orderId, int sellerUserId)
        {
            string date = MyCommonTool.GetOrderDate();
            var userService = GetUserService();
            var ui = userService.GetLoginUser();
            var orderService = GetOrderService();
            bool bSuccess = orderService.IsLegalBuySellInfo(
                        date
                        , orderId
                        , ui.Id
                        , sellerUserId
                     );
            return bSuccess;
        }
    }
}